import sys
input = sys.stdin.readline
inf = float('inf')
def getInt():
return int(input())
def getStr():
return input().strip()
def getList(split=True):
s = getStr()
if split:
s = s.split()
return list(map(int, s))
t = getInt()
def solve():
n, m = getList()
a = getList()
q = getList()
from itertools import accumulate
p = list(accumulate(a))
gain = list(accumulate(p, max))
from bisect import bisect_left, bisect
for i in q:
if i <= gain[-1]:
it = bisect_left(gain, i)
print(it, end=" ")
elif p[-1] <= 0:
print(-1, end=" ")
else:
k = (i-gain[-1] + p[-1]-1) // (p[-1])
i -= p[-1]*k
res = n * k
if i:
res += bisect_left(gain, i)+1
print(res-1, end=" ")
print()
for _ in range(t):
solve()
677C - Vanya and Label | 1583B - Omkar and Heavenly Tree |
1703C - Cypher | 1511C - Yet Another Card Deck |
1698A - XOR Mixup | 1702E - Split Into Two Sets |
1703B - ICPC Balloons | 1702F - Equate Multisets |
1700A - Optimal Path | 665C - Simple Strings |
1708A - Difference Operations | 1703E - Mirror Grid |
1042A - Benches | 1676B - Equal Candies |
1705B - Mark the Dust Sweeper | 1711A - Perfect Permutation |
1701B - Permutation | 1692A - Marathon |
1066A - Vova and Train | 169B - Replacing Digits |
171D - Broken checker | 380C - Sereja and Brackets |
1281B - Azamon Web Services | 1702A - Round Down the Price |
1681C - Double Sort | 12A - Super Agent |
1709A - Three Doors | 1680C - Binary String |
1684B - Z mod X = C | 1003A - Polycarp's Pockets |